const IDS = require("../models/IDS")

//ID自动增长
const incID = async (e) => {
    try {
        const findObject = await IDS.findOne({ object: e });
        if (!findObject) {
            await IDS.create({ object: e, new_id: 100000 })
        }
    }
    catch (err) {
        console.log(err)
    }

    return new Promise((resolve, reject) => {
        IDS.findOneAndUpdate(
            { object: e },
            { $inc: { new_id: 1 } },
            (err, doc) => {
                resolve(doc.new_id);
            }
        );
    });
};

module.exports = incID